﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BTL
{
    public partial class ChiTietHD : Form
    {
        BAL.cthd_BAL _ctdhBAL;
        VO.CtHD_VO _cthdVO;
        public ChiTietHD()
        {
            InitializeComponent();
            cbsearch.Text = "Mã sách";
        }

        private void bt_thoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        private void data()
        {
            _cthdVO = new VO.CtHD_VO();
            _cthdVO.Gia = Convert.ToInt32(box_gia.Text);
            _cthdVO.MaHD = box_mahd.Text;
            _cthdVO.MaS = box_masach.Text;
            _cthdVO.SL = Convert.ToInt32(box_sl.Text);

        }
        private void databinding()
        {
            box_sl.DataBindings.Clear();
            box_sl.DataBindings.Add("text", dataGridViewctHoaDon.DataSource,"SL");
            box_masach.DataBindings.Clear();
            box_masach.DataBindings.Add("text", dataGridViewctHoaDon.DataSource, "MaS");
            box_mahd.DataBindings.Clear();
            box_mahd.DataBindings.Add("text", dataGridViewctHoaDon.DataSource, "MaHD");
            box_gia.DataBindings.Clear();
            box_gia.DataBindings.Add("text", dataGridViewctHoaDon.DataSource, "GIa");
        }
        private void bt_them_Click(object sender, EventArgs e)
        {
            data();
            _ctdhBAL = new BAL.cthd_BAL();
            _ctdhBAL.cthd_them(_cthdVO);
            buttonX1_Click(sender, e);
        }

        private void bt_sua_Click(object sender, EventArgs e)
        {
            data();
            _ctdhBAL = new BAL.cthd_BAL();
            _ctdhBAL.cthd_sua(_cthdVO);
            buttonX1_Click(sender, e);
        }

        private void buttonX1_Click(object sender, EventArgs e)
        {
            _ctdhBAL = new BAL.cthd_BAL();
            dataGridViewctHoaDon.DataSource = _ctdhBAL.cthd_xem();
            
        }

        private void bt_xoa_Click(object sender, EventArgs e)
        {
            _ctdhBAL = new BAL.cthd_BAL();
            _ctdhBAL.cthd_xoa(box_mahd.Text);
            buttonX1_Click(sender, e);
        }

        private void ChiTietHD_Load(object sender, EventArgs e)
        {
            _ctdhBAL = new BAL.cthd_BAL();
            box_mahd.DataSource = _ctdhBAL.ct_hd_mahd();
            box_masach.DataSource = _ctdhBAL.ct_hd_mas();
            buttonX1_Click(sender,e);
            databinding();
        }

        private void bt_timkiem_Click(object sender, EventArgs e)
        {
            if(cbsearch.Text=="Mã sách")
            {
                _ctdhBAL = new BAL.cthd_BAL();
                dataGridViewctHoaDon.DataSource = _ctdhBAL.tk_mas(tbtk.Text);

            }
            else
            {
                _ctdhBAL = new BAL.cthd_BAL();
                dataGridViewctHoaDon.DataSource = _ctdhBAL.tk_mahd(tbtk.Text);
            }
        }
        

    }
}
